package com.study.forumsystemproject.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 * program: forum-system-project
 * <p>
 * description: MD5加密
 * <p>
 * author: xiaoxie
 * <p>
 * create: 2024-08-15 09:53
 **/
public class MD5Util {
    /** 对字符串MD5加密
     * Description: md5
     * Param: * @param input
     * return: java.lang.String
     * Author: xiaoxie
     * Date: 9:55 2024/8/15
    */
    public static String md5(String input) {
        return DigestUtils.md5Hex(input);
    }
    /** 字符串和盐值进行MD5加密.
     * Description: md5AndSalt
     * Param: * @param input
    * @param salt
     * return: java.lang.String
     * Author: xiaoxie
     * Date: 9:57 2024/8/15
    */
    public static String md5AndSalt(String input, String salt) {
        return DigestUtils.md5Hex(md5(input) + salt);
    }
    /** 对输入的密码和SQL的密码进行验证
     * Description: verify
     * Param:  input
     * Author: xiaoxie
     * Date: 10:00 2024/8/15
    */
    public static Boolean verify(String input, String salt, String sql) {
        String s = md5AndSalt(input, salt);
        return sql.equals(s);
    }

}
